package me.zhenqu.redis;

import java.util.Collection;
import java.util.Set;

/**
 * create at: 11-4-20
 *
 * @author Yonghui Chen
 */
public class RedisSet {
    private String category;
    private RedisOperator operator;

    public RedisSet(String category) {
        this.category = "set_" + category;
        operator = RedisOperator.getInstance();
    }

    public void appendItem(String key, String item) {
        operator.add(category, key, item);
    }

    public void appendItems(String key, Collection<String> values) {
        for (String value : values) {
            operator.add(category, key, value);
        }
    }

    public void clear(String key) {
        operator.remove(category, key);
    }

    public Set<String> items(String key) {
        return operator.getSet(category, key);
    }


    public void remove(String key, String value) {
        operator.removeValue(category, key, value);
    }

    public boolean contains(String key, String value) {
        return operator.contains(category, key, value);
    }
}
